﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using System;

namespace KeDa2025_
{
    /// <summary>
    /// DelReplyHandler 的摘要说明
    /// </summary>
    public class DelReplyHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            int replyId = Convert.ToInt32(context.Request["rid"]);
            string connectionString = "server=localhost;user id=zmy2;password=zmy20020525;database=forum;";
            try
            {
                using (MySqlConnection conn = new MySqlConnection(connectionString))
                {
                    conn.Open();
                    string sql = "DELETE FROM replys WHERE id = @ReplyId";
                    using (MySqlCommand cmd = new MySqlCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@ReplyId", replyId);
                        int rows = cmd.ExecuteNonQuery();
                        context.Response.ContentType = "text/plain";
                        context.Response.Write(rows > 0 ? "true" : "false");
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("false");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}